package com.clp.protocol.iec104.apdu.asdu.info_obj.qua;

import com.clp.protocol.core.common.frame.InitializableFrameClip;
import com.clp.protocol.iec104.apdu.asdu.info_obj.TypeTagRequired;
import com.clp.protocol.iec104.definition.TypeTag;

public abstract class Qua implements InitializableFrameClip<Qua>, TypeTagRequired {
    private TypeTag typeTag;

    protected Qua() {}

    @Override
    public TypeTag typeTag() {
        if (typeTag == null) {
            typeTag = TypeTag.gainByQuaClass(this.getClass());
        }
        return typeTag;
    }

    public boolean isTmQua() {
        return this instanceof TmQua;
    }

    public TmQua castToTmQua() {
        return castTo(TmQua.class);
    }

    @SuppressWarnings("unchecked")
    public  <T extends Qua> T castTo(Class<T> clazz) {
        return ((T) this);
    }
}
